import BaseView from "../base/BaseView";
import DropList from "./items/DropList";
import TableLayout from "./table/TableLayout";
import { SWPlateType, SWPlateNames } from "../define/ApiDefine";
import SWPlateModule from "../module/SWPlateModule";
import { TableRowEvent } from "./table/TableRowItem";
const {ccclass, property} = cc._decorator;

@ccclass
export default class SWPlateView extends BaseView {

    @property(TableLayout)
    plateTable: TableLayout = null;
    @property(TableLayout)
    memberTable: TableLayout = null;
    @property(DropList)
    dropPlate: DropList = null;
    onLoad () {
        this.dropPlate.setData(SWPlateNames, 0);
        this.dropPlate.setSelectCallback((index)=>{
            this.updateView();
        });

        this.updateView();
    }

    protected onEnable(): void {
        cc.director.on('TableRowClickEvent', this.onTableRowClickEvent, this);
    }

    protected onDisable(): void {
        cc.director.off('TableRowClickEvent', this.onTableRowClickEvent, this);
    }

    updateView () {
        let type = this.dropPlate.getSelectIndex();
        let data = SWPlateModule.getInstance().getPlateData(type);
        if (data) {
            this.plateTable.showTableData(data);
        }
    }

    onTableRowClickEvent (event: TableRowEvent) {
        if (event.eventKey == 'SWPlateSelect') {
            let ts_code = event.param as string;
            let members = SWPlateModule.getInstance().getPlateMembers(ts_code);
            this.memberTable.showTableData(members);
        }

        // this.dropPlate.setSelectData(data);
        // this.updateView();
    }

}
